package vn.fpt.fsoft.menugame;

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.event.KeyEvent;
import java.awt.image.BufferedImage;
import java.util.ArrayList;
import java.util.List;

import vn.fpt.fsoft.coreframework.Sprite;
/**
 * @author Len Nguyen
 *
 */
public class OptionScreen extends GameScreen {
    
    public static final int COLOR_BLUE = 0;
    public static final int COLOR_GREEN = 1;
    public static final int COLOR_RED = 2;
    public static final int COLOR_YELLOW = 3;
    
    private List<RadioItem> optionItems = new ArrayList<RadioItem>();
    private int optionSelect = COLOR_BLUE;
    private Color resultSelect = Color.BLUE;
    private BufferedImage background;
    private BufferedImage image1;
    private BufferedImage image2;
    
    Sprite sprite = new Sprite();
    
	public OptionScreen(ScreenManager screenManager) {
		super(screenManager);
		// TODO Auto-generated constructor stub
	}

	@Override
	public void gameInit() {
	    
	    background = sprite.getSprite("images/bgOptionScreen.PNG");
	    image1     = sprite.getSprite("images/radio1.PNG");
	    image2     = sprite.getSprite("images/radio2.PNG");
	    
	    RadioItem radioBlue = new RadioItem(image1,image2,227, 180, "Blue", Color.BLACK);
	    optionItems.add(radioBlue);
	    RadioItem radioGreen = new RadioItem(image1,image2, 227, 230,"Green",Color.BLACK);
	    optionItems.add(radioGreen);
	    RadioItem radioRed = new RadioItem(image1,image2, 227, 280,"Red",Color.BLACK);
	    optionItems.add(radioRed);
	    RadioItem radioYellow = new RadioItem(image1,image2, 227, 330,"Yellow", Color.BLACK);
	    optionItems.add(radioYellow);
	}

	@Override
	public void gameUpdate() {
		super.gameUpdate();
		for (int i = 0; i < optionItems.size(); i++) {
		    optionItems.get(i).setSelect(optionSelect == i);
        }
	}

	@Override
	public void gameDraw(Graphics2D g2d) {
	    
		g2d.drawImage(background, 87, 78, null);
		for (int i = 0; i < optionItems.size(); i++) {
		    optionItems.get(i).draw(g2d);
        }
	}
	
	@Override
	public void gameKeyPressed(int keyCode) {
		switch (keyCode) {
		case KeyEvent.VK_UP:
		    optionSelect--;
            if (optionSelect < 0) {
                optionSelect = 0;
            }
			break;
		case KeyEvent.VK_DOWN:
		    optionSelect++;
            if (optionSelect > optionItems.size() - 1) {
                optionSelect = optionItems.size() - 1;
            }
			break;
		case KeyEvent.VK_LEFT:
			// ......
			break;
		case KeyEvent.VK_RIGHT:
		
			break;
		case KeyEvent.VK_ENTER:
		    resultSelect = getOptionItemColor(optionSelect);
		    break;
		case KeyEvent.VK_ESCAPE:
			screenManager.addScreen(new MainMenu(screenManager));
			screenManager.removeScreen(this);
			break;
		}
	}

    @Override
	public void gameShutdown() {
		// TODO Auto-generated method stub
		super.gameShutdown();
	}
    
    private Color getOptionItemColor(int optionSelect) {
        // TODO Auto-generated method stub
        switch (optionSelect) {
            case COLOR_BLUE :
                System.out.println("Mau xanh da troi");
                return Color.BLUE;
            case COLOR_GREEN: 
                System.out.println("Mau xanh la cay");
                return Color.GREEN;
            case COLOR_RED :
                System.out.println("Mau do");
                return Color.RED;
            case COLOR_YELLOW :
                System.out.println("Mau vang");
                return Color.YELLOW;
            default :
                break;
        }
        return resultSelect;
    }
}
